home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trading on the Edge
/
Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin
/
pc
/
mac_file
/
vendor_d
/
neuralwa
/
nw2v50
/
testiris.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-23
|
3KB
|
118 lines
#include <stdio.h>
/****************************************************************
*
* This is a simple test program to test out Flash Code for the
* IRIS problem. To use it, do the following:
*
* - In NeuralWorks create your favorite network to solve the IRIS
* problem
* - Make sure you create a classification Rate matrix
* - Run a Test/One Pass All
* - Note the results of the Classification rate matrix.
* - Run flashcode and output to recall.c
* - Compile recall.c, this module, and link the two to create
* an executable. For example, on a UNIX system, do:
* cc -c recall.c
* cc -c testiris.c
* cc testiris.o recall.o -o testiris -lm
* - Run the compiled program. It should output a classification
* Rate matrix which is identical to NeuralWorks.
*
*****************************************************************
*/
/* Note that this assumes iris_tes has records of the form:
0.165 0.416 0.067 0.043
& 1.0 0.0 0.0
*/
main( )
{
FILE *fp;
float ibuf[4];
float dbuf[3];
float obuf[3];
float cmat[3][3];
float cmatdx[3];
float dval, oval;
int nsamp;
int wx, dx, ox;
char sbuf[102];
if ((fp=fopen("iris_tes.nna", "r"))== (FILE *)0)
exit(1);
nsamp = 0;
for (ox = 0; ox < 3; ox++) {
cmatdx[ox] = 0.0;
for (dx=0; dx < 3; dx++)
cmat[ox][dx] = 0.0;
}
while (fgets(sbuf, 100, fp) != (char *)0) {
if (sscanf(sbuf, "%f %f %f %f", &ibuf[0],&ibuf[1],&ibuf[2],&ibuf[3])
!= 4)
goto read_err;
fgets(sbuf, 100, fp); /* output line */
if (sscanf(sbuf, "& %f %f %f", &dbuf[0],&dbuf[1],&dbuf[2])
!= 3)
goto read_err;
NN_Recall( (void *)0, ibuf, obuf );
/* Find index of desired class */
dval = oval = -10000.0;
for (wx=0; wx < 3; wx++) {
if (dbuf[wx] > dval) {
dval = dbuf[wx];
dx = wx;
}
if (obuf[wx] > oval) {
oval = obuf[wx];
ox = wx;
}
}
cmat[ox][dx] += 1.0;
cmatdx[dx] += 1.0;
nsamp++;
}
if (nsamp != 0) {
float avcrt = 0.0;
for (ox = 2; ox>=0; ox--) {
printf("\n");
if (cmatdx[ox] > 0.1)
cmatdx[ox] = 1.0/cmatdx[ox];
for (dx=0; dx < 3; dx++) {
float wr;
wr = cmat[ox][dx] * cmatdx[ox];
printf(" %f", wr);
if (dx == ox)
avcrt += wr;
}
}
printf("\n\n *** Average Classifiation Rate = %f ***\n\n",
avcrt/3.0);
} else
printf("No samples found\n");
exit(0);
read_err:
printf("Error reading file <iris_tes.nna>\n");
exit(1);
}